import gnomevfs

def gen():
    i = 0
    while True:
        yield i
        i += 1

g = gen()

class Child:

    def getId(self):
        return g.next()

class SessionHandle:

    children = None

    def __init__(self, name, ssn):
        self.name = name
        self.ssn = ssn
        self.count = 0

    def iterChildren(self):
        while self.count < 10:
            print self.count
            self.count += 1
            yield Child()
        raise StopIteration

class fs_method:

    def __init__(self, module, handle):
        pass

    def vfs_open_directory(self, uri, *args):
        print 'open_directory'
        return SessionHandle(uri.path, None)

    def vfs_close_directory(self, handle, context):
        print 'close_directory', handle, context

    def vfs_read_directory(self, handle, fileinfo, context):
        print 'read_directory'
        if handle.children is None:
            handle.children = handle.iterChildren()

        try:
            child = handle.children.next()
        except StopIteration:
            raise gnomevfs.EOFError

        fileinfo.name = str(child.getId())
        fileinfo.type = gnomevfs.FILE_TYPE_DIRECTORY

    def vfs_is_local(self, *args):
        print 'is_local'
        return 0

    def vfs_get_file_info(self, uri, file_info, hmm, context):
        print 'get_file_info'
        file_info.type = gnomevfs.FILE_TYPE_DIRECTORY
        file_info.name = uri.path.strip('/')
        file_info.size = 0

    def vfs_open(self, *args):
        print 'open'

    def vfs_close(self, *args):
        print 'close'

    def vfs_create(self, *args):
        print 'create'

    def vfs_read(self, *args):
        print 'read'

    def vfs_write(self, *args):
        print 'write'

    def vfs_seek(self, *args):
        print 'seek'

    def vfs_tell(self, *args):
        print 'tell'

    def vfs_truncate_handle(self, *args):
        print 'truncate_handle'

    def vfs_get_file_info_from_handle(self, *args):
        print 'get_file_info_from_handle'

    def vfs_make_directory(self, *args):
        print 'make_directory'

    def vfs_find_directory(self, *args):
        print 'find_directory'

    def vfs_remove_directory(self, *args):
        print 'remove_directory'

    def vfs_move(self, *args):
        print 'move'

    def vfs_unlink(self, *args):
        print 'unlink'

    def vfs_check_same_fs(self, *args):
        print 'check_same_fs'

    def vfs_set_file_info(self, *args):
        print 'set_file_info'

    def vfs_truncate(self, *args):
        print 'truncate'

    def vfs_create_symbolic_link(self, *args):
        print 'create_symbolic_link'

    def vfs_file_control(self, *args):
        print 'file control', args
        return 'fs ok'
